package com.ruoyi.zhgd.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.ruoyi.zhgd.domain.NAsphaltMatch;
import com.ruoyi.zhgd.domain.NAsphaltMatchThreshold;
import com.ruoyi.zhgd.domain.NAsphaltMatchType;
import com.ruoyi.zhgd.domain.NSysStation;
import com.ruoyi.zhgd.domain.vo.NAsphaltDataSievingAvgVo;
import com.ruoyi.zhgd.domain.vo.NAsphaltDayStatisticsDetailsVo;
import com.ruoyi.zhgd.domain.vo.NAsphaltDayStatisticsVo;
import com.ruoyi.zhgd.mapper.NAsphaltDayStatisticsMapper;
import com.ruoyi.zhgd.service.*;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 全天生产数据业务接口实现
 *
 * @author tll
 * @date 2023-10-12
 */
@RequiredArgsConstructor
@Service
@DS("sjcj")
public class NAsphaltDayStatisticsServiceImpl implements NAsphaltDayStatisticsService {

    private final NAsphaltDayStatisticsMapper baseMapper;

    private final INAsphaltMatchService inAsphaltMatchService;

    private final INAsphaltMatchThresholdService inAsphaltMatchThresholdService;

    private final INAsphaltMatchTypeService inAsphaltMatchTypeService;

    private final INAsphaltMatchHotService inAsphaltMatchHotService;

    private final INSysStationService inSysStationService;

    private final INAsphaltDataSieveService inAsphaltDataSieveService;

    /**
     * 获取分页列表
     *
     * @param stationCode
     * @param matchCode
     * @param day
     * @return
     */
    @Override
    public NAsphaltDayStatisticsVo getDayChartData(String stationCode, String matchCode, String day) {
        // 返回结果
        NAsphaltDayStatisticsVo vo = new NAsphaltDayStatisticsVo();

        // 获取配方编号
        NAsphaltMatch match = inAsphaltMatchService.getByCode(matchCode);

        if (ObjectUtils.isNotEmpty(match)) {
            // 获取上下限
            NAsphaltMatchThreshold matchThreshold = inAsphaltMatchThresholdService.getByMatchName(match.getMatchName());
            vo.setMatchThreshold(matchThreshold);
            // 获取级配类型
            NAsphaltMatchType matchType = inAsphaltMatchTypeService.getByType(match.getMatchType());
            vo.setMatchType(matchType);
            // 获取热料配置信息
            Map<String, Double> targetMap = inAsphaltMatchHotService.getTargetMap(match.getId());
            vo.setTargetMap(targetMap);

            stationCode = match.getStationCode();
        }
        vo.setMatch(match);

        // 获取拌合楼信息
        NSysStation station = null;
        if (ObjectUtils.isNotEmpty(stationCode)) {
            station = inSysStationService.getStationByCode(stationCode);
        }
        vo.setStation(station);

        // 获取筛分数据
        NAsphaltDataSievingAvgVo sieveDataAvg = inAsphaltDataSieveService.avgForDay(matchCode, matchCode, day);
        vo.setSieveDataAvg(sieveDataAvg);

        // 获取全部生产数据
        List<NAsphaltDayStatisticsDetailsVo> details = baseMapper.getDetails(stationCode, matchCode, day);
        vo.setDetails(details);

        return vo;
    }
}
